package com.tanhua.admin.listener;

import com.tanhua.admin.mapper.LogMapper;
import com.tanhua.model.domain.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Slf4j
public class LogListener {

    @Autowired(required = false)
    private LogMapper logMapper;

    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "tanhua.log.queue"),
    exchange = @Exchange(name = "tanhua.log.exchange",type = ExchangeTypes.TOPIC),key = "log.*"))
    public void listenerCreate(Map<String,Object> paraMap){

        log.info("=====准备插入日志信息====>"+paraMap);
        Long userId = Long.valueOf(paraMap.get("userId").toString());
        String logTime =paraMap.get("logTime").toString();
        String type =paraMap.get("type").toString();
        Log log = new Log();
        log.setUserId(userId);
        log.setLogTime(logTime);
        log.setType(type);
        logMapper.insert(log);


    }
}
